//
//  WelcomeViewController.swift
//  HMWeibo06
//
//  Created by apple on 15/5/13.
//  Copyright (c) 2015年 heima. All rights reserved.
//

import UIKit
import SDWebImage

class WelcomeViewController: UIViewController {

    @IBOutlet weak var iconImage: UIImageView!
    @IBOutlet weak var bottomConstraint: NSLayoutConstraint!
    @IBOutlet weak var welcomeLabel: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        // 判断是否存在用户账户信息
        if let urlString = sharedUserAccount?.avatar_large {
            iconImage.sd_setImageWithURL(NSURL(string: urlString))
        }
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        bottomConstraint.constant = view.bounds.size.height - bottomConstraint.constant
        
        UIView.animateWithDuration(2.0, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 5.0, options: nil, animations: {
            self.view.layoutIfNeeded()
        }) { _ in

            UIView.animateWithDuration(1.0, animations: {
                self.welcomeLabel.alpha = 1.0
            }, completion: { (_) in
                // 切换界面需要集中管理
                NSNotificationCenter.defaultCenter().postNotificationName(HMSwitchRootViewControllerNotification, object: "Main")
            })
        }
    }
}
